package me.zk.practice1.hw;

import java.util.Scanner;

/**
 * @author zhangkai
 * @date 2023/8/8 13:08
 */
public class HWBJ42 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

       String s1 = scanner.nextLine();
       String[] strings= s1.split(" ");
       int m = Integer.parseInt(strings[0]);
       int n= Integer.parseInt(strings[1]);
;      int[][] nums = new int[m][n];

        for (int i = 0; i < m; i++) {
            String s = scanner.nextLine();
            String[] ss = s.split(" ");
            for (int j = 0; j < ss.length; j++) {
                nums[i][j] = Integer.parseInt(ss[j]);
            }
        }

        int res = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (nums[i][j] == 1) {
                    res++;
                } else if (i>0 && nums[i-1][j]==1) {
                    //上方
                    res++;
                } else if (i < m-1 &&nums[i+1][j]==1) {
                    //下方
                    res++;
                } else if(j>0&&nums[i][j-1]==1){
                    //左方
                    res++;
                } else if (j < n-1 &&nums[i][j+1]==1){
                    //右方
                    res++;
                }

            }
        }
        System.out.println(res);
    }
}
